//
//  mainTabBar.swift
//  weiboxiangmu
//
//  Created by wei_jingyun on 15/6/23.
//  Copyright © 2015年 wei_jingyun. All rights reserved.
//

import UIKit

class mainTabBar: UITabBar {

    override func layoutSubviews() {
        super.layoutSubviews()
        /// Debug.Log(subviews)
        /// UITabBarButton 为私有类 使用可能导致无法上架
        /// 按键数量
        let tt = 5
        let w = bounds.width / CGFloat(tt)
        let rect = CGRectMake(0, 0, w, bounds.height)
    
        /// 遍历调整 subviews 的位置
        var index = -1
        for v in subviews {
            if v is UIControl {
                /// 偏移
                v.frame = CGRectOffset(rect, CGFloat(index) * w, 0)
                index += index == 1 ? 2 : 1
            }
        }
       
        /// 懒加载 but
        commBut.frame = CGRectOffset(rect, 2 * w , 0)
        
    }
    
    /// 懒加载 lazy
    lazy var commBut :UIButton = {
        let btn = UIButton()
        /// 闭包内需要使用 self
        self.addSubview(btn)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        return btn
    }()

}
